package b.i.h;

import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Typeface;
import android.net.Uri;
import b.f.f;
import b.f.h;
import com.huawei.hms.android.HwBuildEx.VersionCodes;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Objects;

/* compiled from: FontsContractCompat */
public class e {
    public static final f<String, Typeface> a = new f(16);
    public static final f b = new f("fonts", 10, VersionCodes.CUR_DEVELOPMENT);
    public static final Object c = new Object();
    public static final h<String, ArrayList<b.i.h.f.c<d>>> d = new h();
    public static final Comparator<byte[]> e = new a();

    /* compiled from: FontsContractCompat */
    public class a implements Comparator<byte[]> {
        public int compare(Object obj, Object obj2) {
            int length;
            int length2;
            byte[] bArr = (byte[]) obj;
            byte[] bArr2 = (byte[]) obj2;
            if (bArr.length != bArr2.length) {
                length = bArr.length;
                length2 = bArr2.length;
            } else {
                int i = 0;
                while (i < bArr.length) {
                    if (bArr[i] != bArr2[i]) {
                        length = bArr[i];
                        length2 = bArr2[i];
                    } else {
                        i++;
                    }
                }
                return 0;
            }
            return length - length2;
        }
    }

    /* compiled from: FontsContractCompat */
    public static class b {
        public final int a;
        public final c[] b;

        public b(int i, c[] cVarArr) {
            this.a = i;
            this.b = cVarArr;
        }
    }

    /* compiled from: FontsContractCompat */
    public static class c {
        public final Uri a;
        public final int b;
        public final int c;
        public final boolean d;
        public final int e;

        public c(Uri uri, int i, int i2, boolean z, int i3) {
            Objects.requireNonNull(uri);
            this.a = uri;
            this.b = i;
            this.c = i2;
            this.d = z;
            this.e = i3;
        }
    }

    /* compiled from: FontsContractCompat */
    public static final class d {
        public final Typeface a;
        public final int b;

        public d(Typeface typeface, int i) {
            this.a = typeface;
            this.b = i;
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:25:0x0090 A:{LOOP_END, LOOP:1: B:12:0x004b->B:25:0x0090} */
    /* JADX WARNING: Removed duplicated region for block: B:73:0x0094 A:{SYNTHETIC, EDGE_INSN: B:73:0x0094->B:27:0x0094 ?: BREAK  } */
    public static b.i.h.e.b a(android.content.Context r20, android.os.CancellationSignal r21, b.i.h.a r22) throws android.content.pm.PackageManager.NameNotFoundException {
        /*
        r0 = r22;
        r1 = r20.getPackageManager();
        r2 = r20.getResources();
        r3 = r0.a;
        r4 = 0;
        r5 = r1.resolveContentProvider(r3, r4);
        if (r5 == 0) goto L_0x01ad;
    L_0x0013:
        r6 = r5.packageName;
        r7 = r0.b;
        r6 = r6.equals(r7);
        if (r6 == 0) goto L_0x0196;
    L_0x001d:
        r3 = r5.packageName;
        r6 = 64;
        r1 = r1.getPackageInfo(r3, r6);
        r1 = r1.signatures;
        r3 = new java.util.ArrayList;
        r3.<init>();
        r6 = 0;
    L_0x002d:
        r7 = r1.length;
        if (r6 >= r7) goto L_0x003c;
    L_0x0030:
        r7 = r1[r6];
        r7 = r7.toByteArray();
        r3.add(r7);
        r6 = r6 + 1;
        goto L_0x002d;
    L_0x003c:
        r1 = e;
        java.util.Collections.sort(r3, r1);
        r1 = r0.d;
        if (r1 == 0) goto L_0x0046;
    L_0x0045:
        goto L_0x004a;
    L_0x0046:
        r1 = b.i.b.f.P0(r2, r4);
    L_0x004a:
        r2 = 0;
    L_0x004b:
        r6 = r1.size();
        r7 = 0;
        r8 = 1;
        if (r2 >= r6) goto L_0x0093;
    L_0x0053:
        r6 = new java.util.ArrayList;
        r9 = r1.get(r2);
        r9 = (java.util.Collection) r9;
        r6.<init>(r9);
        r9 = e;
        java.util.Collections.sort(r6, r9);
        r9 = r3.size();
        r10 = r6.size();
        if (r9 == r10) goto L_0x006e;
    L_0x006d:
        goto L_0x0087;
    L_0x006e:
        r9 = 0;
    L_0x006f:
        r10 = r3.size();
        if (r9 >= r10) goto L_0x008c;
    L_0x0075:
        r10 = r3.get(r9);
        r10 = (byte[]) r10;
        r11 = r6.get(r9);
        r11 = (byte[]) r11;
        r10 = java.util.Arrays.equals(r10, r11);
        if (r10 != 0) goto L_0x0089;
    L_0x0087:
        r6 = 0;
        goto L_0x008d;
    L_0x0089:
        r9 = r9 + 1;
        goto L_0x006f;
    L_0x008c:
        r6 = 1;
    L_0x008d:
        if (r6 == 0) goto L_0x0090;
    L_0x008f:
        goto L_0x0094;
    L_0x0090:
        r2 = r2 + 1;
        goto L_0x004b;
    L_0x0093:
        r5 = r7;
    L_0x0094:
        if (r5 != 0) goto L_0x009c;
    L_0x0096:
        r0 = new b.i.h.e$b;
        r0.m491init(r8, r7);
        return r0;
    L_0x009c:
        r1 = r5.authority;
        r2 = new java.util.ArrayList;
        r2.<init>();
        r3 = new android.net.Uri$Builder;
        r3.<init>();
        r5 = "content";
        r3 = r3.scheme(r5);
        r3 = r3.authority(r1);
        r3 = r3.build();
        r6 = new android.net.Uri$Builder;
        r6.<init>();
        r5 = r6.scheme(r5);
        r1 = r5.authority(r1);
        r5 = "file";
        r1 = r1.appendPath(r5);
        r1 = r1.build();
        r9 = r20.getContentResolver();	 Catch:{ all -> 0x018f }
        r10 = "_id";
        r11 = "file_id";
        r12 = "font_ttc_index";
        r13 = "font_variation_settings";
        r14 = "font_weight";
        r15 = "font_italic";
        r16 = "result_code";
        r11 = new java.lang.String[]{r10, r11, r12, r13, r14, r15, r16};	 Catch:{ all -> 0x018f }
        r12 = "query = ?";
        r13 = new java.lang.String[r8];	 Catch:{ all -> 0x018f }
        r0 = r0.c;	 Catch:{ all -> 0x018f }
        r13[r4] = r0;	 Catch:{ all -> 0x018f }
        r14 = 0;
        r15 = 0;
        r10 = r3;
        r7 = r9.query(r10, r11, r12, r13, r14, r15);	 Catch:{ all -> 0x018f }
        if (r7 == 0) goto L_0x017c;
    L_0x00f4:
        r0 = r7.getCount();	 Catch:{ all -> 0x018f }
        if (r0 <= 0) goto L_0x017c;
    L_0x00fa:
        r0 = "result_code";
        r0 = r7.getColumnIndex(r0);	 Catch:{ all -> 0x018f }
        r2 = new java.util.ArrayList;	 Catch:{ all -> 0x018f }
        r2.<init>();	 Catch:{ all -> 0x018f }
        r5 = "_id";
        r5 = r7.getColumnIndex(r5);	 Catch:{ all -> 0x018f }
        r6 = "file_id";
        r6 = r7.getColumnIndex(r6);	 Catch:{ all -> 0x018f }
        r9 = "font_ttc_index";
        r9 = r7.getColumnIndex(r9);	 Catch:{ all -> 0x018f }
        r10 = "font_weight";
        r10 = r7.getColumnIndex(r10);	 Catch:{ all -> 0x018f }
        r11 = "font_italic";
        r11 = r7.getColumnIndex(r11);	 Catch:{ all -> 0x018f }
    L_0x0123:
        r12 = r7.moveToNext();	 Catch:{ all -> 0x018f }
        if (r12 == 0) goto L_0x017c;
    L_0x0129:
        r12 = -1;
        if (r0 == r12) goto L_0x0133;
    L_0x012c:
        r13 = r7.getInt(r0);	 Catch:{ all -> 0x018f }
        r19 = r13;
        goto L_0x0136;
    L_0x0133:
        r13 = 0;
        r19 = 0;
    L_0x0136:
        if (r9 == r12) goto L_0x013f;
    L_0x0138:
        r13 = r7.getInt(r9);	 Catch:{ all -> 0x018f }
        r16 = r13;
        goto L_0x0142;
    L_0x013f:
        r13 = 0;
        r16 = 0;
    L_0x0142:
        if (r6 != r12) goto L_0x014d;
    L_0x0144:
        r13 = r7.getLong(r5);	 Catch:{ all -> 0x018f }
        r13 = android.content.ContentUris.withAppendedId(r3, r13);	 Catch:{ all -> 0x018f }
        goto L_0x0155;
    L_0x014d:
        r13 = r7.getLong(r6);	 Catch:{ all -> 0x018f }
        r13 = android.content.ContentUris.withAppendedId(r1, r13);	 Catch:{ all -> 0x018f }
    L_0x0155:
        r15 = r13;
        if (r10 == r12) goto L_0x015f;
    L_0x0158:
        r13 = r7.getInt(r10);	 Catch:{ all -> 0x018f }
        r17 = r13;
        goto L_0x0163;
    L_0x015f:
        r13 = 400; // 0x190 float:5.6E-43 double:1.976E-321;
        r17 = 400; // 0x190 float:5.6E-43 double:1.976E-321;
    L_0x0163:
        if (r11 == r12) goto L_0x016f;
    L_0x0165:
        r12 = r7.getInt(r11);	 Catch:{ all -> 0x018f }
        if (r12 != r8) goto L_0x016f;
    L_0x016b:
        r12 = 1;
        r18 = 1;
        goto L_0x0172;
    L_0x016f:
        r12 = 0;
        r18 = 0;
    L_0x0172:
        r12 = new b.i.h.e$c;	 Catch:{ all -> 0x018f }
        r14 = r12;
        r14.m492init(r15, r16, r17, r18, r19);	 Catch:{ all -> 0x018f }
        r2.add(r12);	 Catch:{ all -> 0x018f }
        goto L_0x0123;
    L_0x017c:
        if (r7 == 0) goto L_0x0181;
    L_0x017e:
        r7.close();
    L_0x0181:
        r0 = new b.i.h.e.c[r4];
        r0 = r2.toArray(r0);
        r0 = (b.i.h.e.c[]) r0;
        r1 = new b.i.h.e$b;
        r1.m491init(r4, r0);
        return r1;
    L_0x018f:
        r0 = move-exception;
        if (r7 == 0) goto L_0x0195;
    L_0x0192:
        r7.close();
    L_0x0195:
        throw r0;
    L_0x0196:
        r1 = new android.content.pm.PackageManager$NameNotFoundException;
        r2 = "Found content provider ";
        r4 = ", but package was not ";
        r2 = c.b.a.a.a.j(r2, r3, r4);
        r0 = r0.b;
        r2.append(r0);
        r0 = r2.toString();
        r1.<init>(r0);
        throw r1;
    L_0x01ad:
        r0 = new android.content.pm.PackageManager$NameNotFoundException;
        r1 = "No package found for authority: ";
        r1 = c.b.a.a.a.D(r1, r3);
        r0.<init>(r1);
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.i.h.e.a(android.content.Context, android.os.CancellationSignal, b.i.h.a):b.i.h.e$b");
    }

    public static d b(Context context, a aVar, int i) {
        try {
            b a = a(context, null, aVar);
            int i2 = a.a;
            int i3 = -3;
            if (i2 == 0) {
                Typeface b = b.i.d.d.a.b(context, null, a.b, i);
                if (b != null) {
                    i3 = 0;
                }
                return new d(b, i3);
            }
            if (i2 == 1) {
                i3 = -2;
            }
            return new d(null, i3);
        } catch (NameNotFoundException unused) {
            return new d(null, -1);
        }
    }
}
